package com.example.mymicaihu.callback;

import com.example.myhttplibrary.callback.BaseCallBack;
import com.example.myhttplibrary.callback.BaseResponse;
import com.google.gson.Gson;

/**
 * 作者：朱勇闯
 * data : 2021/4/25  9:31
 * 作用： xxxx
 */
public abstract class HttpCallBack<T> extends BaseCallBack<T> {
    BaseResponse baseResponse;

    @Override
    protected T onConvert(String result) {
        T t = null;
        baseResponse = new Gson().fromJson(result, BaseResponse.class);
        if (baseResponse != null && isSuccessFull()) {
            t = convert(baseResponse.getData());
        } else {
            error(baseResponse.getErrorMsg(), baseResponse.getErrorCode());
        }
        return t;
    }

    @Override
    public boolean isSuccessFull() {
        return baseResponse.getErrorCode() == 0;
    }
}
